package com.hzncc.flowable_diboot.custom_field.service.impl;

import com.diboot.core.service.impl.BaseServiceImpl;
import com.hzncc.flowable_diboot.custom_field.entity.CustomField;
import com.hzncc.flowable_diboot.custom_field.mapper.CustomFieldMapper;
import com.hzncc.flowable_diboot.custom_field.service.CustomFieldService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 字段配置 相关Service实现类
 *
 * @author MyName
 * @version 1.0
 * @date 2024-10-09
 * Copyright © MyCorp
 */
@Slf4j
@Service
public class CustomFieldServiceImpl extends BaseServiceImpl<CustomFieldMapper, CustomField> implements CustomFieldService {

    /**
     * 根据业务类型获取字段列表
     *
     * @param type
     * @return
     */
    @Override
    public List<CustomField> getCustomFieldListByType(String type) {
        return getEntityList(lambdaQuery().eq(CustomField::getType, type));
    }

    @Override
    public Map<String, CustomField> getCustomFieldMapByType(String type) {
        List<CustomField> customFieldListByType = getCustomFieldListByType(type);
        if (customFieldListByType != null) {
            return customFieldListByType.stream().collect(Collectors.toMap(CustomField::getFieldName, e -> e));
        }
        return null;
    }
}